<template>
	<view>
		<u-toast ref="uToast" />
		<view v-if="show" class="loading_view" style="padding:220rpx 0;">
		  <u-loading mode="circle" size="50"></u-loading>
		  <view class="messgae">
			加载中...
		  </view>
		 </view>
		<view v-else>
			<view class="coupons_box">
				
				<view v-for="(v,k) in list" :key="k" :class="v.isChose==1?'coupons_item sel':'coupons_item'">
					<view class="item_left">
						<view class="money">{{ v.c_name }}</view>
						<view class="describe">.凭券可享受减{{ v.c_money }}元优惠</view>
						<view class="describe">.满{{ v.c_above_money }}元可用</view>
						<view class="describe">.有效期至{{ $u.timeFormat(v.c_endTime, 'yyyy年mm月dd日 hh:MM') }}</view>
						<view class="describe">.可与其他优惠活动同享</view>
					</view>
					
					<view class="item_right">
						<view class="money">￥{{ v.c_money }}</view>
						<view class="butt" v-if="v.isUse==1" @click="onUse" :data-id="v.c_id" :data-index="k">使用</view>
						<view class="butt" v-else>已过期</view>
					</view>
					
				</view>
				
			</view>
		</view>
	</view>
</template>

<script>
	export default{
		data(){
			return{
				cid:null,
				chose:null,
				list:[],
				member:[],
				show:true,
				chose_id:null
			}
		},onLoad(e){
			var cid=typeof(e.cid)
			
			var chose=typeof(e.chose)
			
			if(cid!='undefined' && chose!='undefined'){
				this.cid=Number(e.cid)
				
				this.chose=Number(e.chose)
				
				this.onCoupons();
			}else{
				this.$refs.uToast.show({
					title: '数据错误,即将返回',
					type: 'warning'
				})
				
				setTimeout(function(){
					uni.navigateBack({
						delta:1
					})
				},1300);
			}
		},methods:{
			onUse(e){
				var id=e.currentTarget.dataset.id;
				
				var index=e.currentTarget.dataset.index;
				
				var money=this.list[index].c_above_money;
				
				if(money>this.member.price){
					return this.$refs.uToast.show({
						title: '未达到使用条件',
						type: 'default'
					});
				}
				
				uni.redirectTo({
					url:'/pages/user/my_member?id='+id+"&chose="+this.chose
				})
			},
			onCoupons(){
				var that=this;
				
				this.$request({
					url:'/user/coupons',
					data:{cid:this.cid,chose:this.chose},
					success(res){
						if(res.data.code==1){
							that.list=res.data.data.list;
							
							that.member=res.data.data.member;
							
							that.show=false;
						}else{
							that.$refs.uToast.show({
								title: res.data.msg,
								type: 'warning'
							})
						}
					},fail(){
						that.$refs.uToast.show({
							title: '数据错误,即将返回',
							type: 'warning'
						})
					}
				})
			}
		}
	}
</script>

<style scoped>
	view.coupons_box{
		display: flex;
		flex-direction: column;
		align-items: center;
	}
	view.coupons_box view.coupons_item{
		width:670rpx;
		padding: 20rpx;
		min-height: 220rpx;
		background-color: #fff;
		border-radius: 15rpx;
		margin-top: 20rpx;
		display: flex;
		font-size: 24rpx;
		justify-content: space-between;
		border:2rpx solid #F2F2F2;
	}
	.sel{
		border-color:#EA4389;
		background:#F4CFDE;
	}
	view.coupons_box view.coupons_item view.item_left view.money{
		max-width: 360rpx;
		font-size: 34rpx;
		font-weight: bold;
		margin-bottom: 30rpx;
		white-space: nowrap;
		overflow: hidden;
		text-overflow: ellipsis;
	}
	view.disabled view.coupons_item view.item_left view.money{
		color:#888;
	}
	view.coupons_box view.coupons_item view.item_left view.describe{
		color:#888888;
		margin-top: 5rpx;
	}
	view.coupons_box view.coupons_item view.item_right .money{
		color:#EA4389;
		font-size: 30rpx;
		/* font-weight: bold; */
	}
	view.disabled view.coupons_item view.item_right .money{
		color: #888;
	}
	view.coupons_box view.coupons_item view.item_right {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}
	view.coupons_box view.coupons_item view.item_right .butt{
		padding: 10rpx 30rpx;
		background-color: #EA4389;
		color:#fff;
		border-radius: 30rpx;
		margin-top: 15rpx;
	}
	view.disabled view.coupons_item view.item_right .butt{
		background-color: #888;
	}
</style>
